<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="lib/layui/css/admin.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<script type="text/html" id="switchStatus">
    {{# if(d.statusName== '待完成' ){ }}
    <a class="layui-btn layui-btn-xs" lay-event="complete">确认完成</a>

    {{# }else { }}

    {{# } }}
</script>
<fieldset class="layui-elem-field layui-field-title">
    <legend>上架任务</legend>
</fieldset>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-card-body">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>


<!--<button type="button" class="layui-btn"  onclick="insertDelivery()">批量收货</button>-->
<!--<table class="layui-hide" id="test1" lay-filter="test"></table>-->



<table>

</table>
<script src="lib/jquery-1.12.4.js"></script>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->


<script>
    layui.use('table', function() {
        var table = layui.table;

        //监听行工具事件
        table.render({
            elem: '#test'
            , url: 'pk/taskOnShelives/listTaskOnShelives'
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count":  res.total, //解析数据长度
                    "data": res.obj.list //解析数据列表
                };
            },page :true
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                {type: 'checkbox'}
                // , {field: 'whEntryCode', title: '入库单号', sort: true}
                , {field: 'goodsAllocationCode', title: '上架货架', sort: true}
                , {field: 'goodsName', title: '上架商品名称', sort: true}
                , {field: 'quantityOnShelives', title: '上架商品数量', sort: true}
                , {field: 'userName', title: '上架人员', sort: true,templet :function (res) {
                        if(res.username==null){
                            return '无'
                        }
                    }}
                , {field: 'statusName', title: '状态', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#switchStatus', width:150}
            ]]
        });
        table.on('tool(test)', function(obj){

            var data1 = obj.data;
            var data2 = [];
            data2.push({"id":data1.id,"shelfId":data1.shelfId,"quantityOnShelives":data1.quantityOnShelives,"warehouseEntryId":data1.warehouseEntryId});
            console.log(data2);

            var data = JSON.stringify(data2);
            if(obj.event === 'com'){
                // layer.confirm('真的删除行么', function(index){
                //     obj.del();
                //     layer.close(index);
                // });
            } else if(obj.event === 'complete'){
                var staffId = 2;

                $.ajax({
                    url: 'pk/taskOnShelives/onShelfCompleted?staffId='+staffId,
                    type: "POST",
                    data: data,
                    contentType:"application/json;charset=UTF-8",
                    success:function (data) {
                        layer.msg("任务完成");
                        selectOnShelf();
                        if (data.obj==1) {

                        }else {
                            layer.msg(data.mes);
                        }


                    }
                });
            }
        });

    });
    function selectOnShelf() {
        var table = layui.table;
        table.reload('test',function () {
            page:{
                curr :1
            }
        })
    }
</script>
</body>
</html>